/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewSumStudent.java
 *
 * Created on 03 10, 13, 2:07:22 PM
 */
package Forms;

import Classes.MInterface;
import Classes.SchoolYear;
import Classes.SumSubject;
import Classes.Summer;
import Classes.SummerSy;
import Classes.User;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Lenovo
 */
public class SumStudent extends javax.swing.JFrame {

    static MInterface mi;
    static User cUser;
    static Summer id;
    static String ae;
    static String ssy;
    
    String port;
    _Login l = new _Login();
    
    ArrayList<Object> smList; 
    ArrayList<Object> ssList; 
    ArrayList<Object> cbl;
        
    DefaultListModel dlmr;
    DefaultListModel dlma;
    ArrayList<SummerSy> sy;
    
    /** Creates new form NewSumStudent */
    public SumStudent(User user, MInterface i, String sid, String yr) {        
        
//        this.setLocationRelativeTo(getRootPane());
        initComponents();
        ssy = yr;
        ae = sid;
        mi = i;
        cUser = user;
        jButton6.setVisible(false);
        
        try {
//            if (mi.getCurrentDate().compareTo(mi.getEndSummer(mi.getCurrentDate())) < 0) {                
//                schoolYearL.setText("Summer: " + mi.getToday());
//            }
            
//            String ssy = null;
//            sy = mi.listSummerSy();
//            for(int p = 0; p < sy.size(); p++) {
//                ssy = sy.get(p).getSyName();
//            }
            
            schoolYearL.setText(ssy);
            
                dlma = new DefaultListModel();
                jList2.setModel(dlma);
                
            if(!ae.isEmpty()) {  
                    id = (Summer) mi.get("get-summer", sid, yr);
                //String[] bb = id.getSBDate().split("-");
                    schoolYearL.setText(id.getSSYID());
                    save.setText("Edit");
                    IDNoT.setText(id.getSSID());
                    lNameT.setText(id.getSSLName());
                    gNameT.setText(id.getSSGName());
                    mNameT.setText(id.getSSMName());
                /*bMonthCB.setSelectedItem(sMonth(bb[1]));
                bMonthCB.setForeground(Color.MAGENTA);
                bDayCB.setSelectedItem(bb[2]);
                bDayCB.setForeground(Color.MAGENTA);                
                bYearCB.setSelectedItem(bb[0]);
                bYearCB.setForeground(Color.MAGENTA);*/
                    genderCB.setSelectedItem(id.getSGen());
                    genderCB.setForeground(Color.MAGENTA);
//                faNameT.setText(id.getSFName());
                //moNameT.setText(id.getSMName());
                    IDNoT.setEnabled(false);
                    lNameT.setEnabled(false);
                    gNameT.setEnabled(false);
                    mNameT.setEnabled(false);
                /*bMonthCB.setEnabled(false);
                bDayCB.setEnabled(false);
                bYearCB.setEnabled(false);*/
                    genderCB.setEnabled(false);
                    parentT.setText(id.getSParent());
                    parentT.setEnabled(false);
                    cNo.setText(id.getSParentCno());
                    cNo.setEnabled(false);
                //moNameT.setEnabled(false);
                    jList1.setEnabled(false);
                    jList2.setEnabled(false);
                    jButton1.setEnabled(false);
                    jButton2.setEnabled(false);
                    jButton3.setEnabled(false);
//                jButton4.setEnabled(false);
                    jButton6.setEnabled(false);
                
                ssList = mi.SSSList(id.getSSID());
                ArrayList<SumSubject> ssl = new ArrayList<SumSubject>();
                for(int x = 0; x < ssList.size(); x++) {
                    ssl.add((SumSubject) ssList.get(x));
                }
            
                for(int x = 0; x < ssl.size(); x++) {
                    dlma.addElement(ssl.get(x).getSumSub());
                }
            }
                                    
            /*String[] yr = mi.getCurrentDate().split(" ");
            bYearCB.removeAllItems();
            int yr1 = Integer.parseInt(yr[2]);
            for(int y = 0; y < 20; y++) {
                String sYR = (yr1 - y) + "";
                bYearCB.addItem(sYR);
            }*/
//            sy = mi.listSummerSy();
//            for(int p = 0; p < sy.size(); p++) {
//                ssy = sy.get(p).getSyName();
//            }
            
//            ssList = mi.SSSList(id.getSSID());
//            ArrayList<SumSubject> ssl = new ArrayList<SumSubject>();
//            for(int x = 0; x < ssList.size(); x++) {
//                ssl.add((SumSubject) ssList.get(x));
//            }
//            dlma = new DefaultListModel();
//            jList2.setModel(dlma);
//            for(int x = 0; x < ssl.size(); x++) {
//                dlma.addElement(ssl.get(x).getSumSub());
//            }
//            
            updateTbl();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bannerL = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        genderL = new javax.swing.JLabel();
        mNameL = new javax.swing.JLabel();
        gNameL = new javax.swing.JLabel();
        fNameL = new javax.swing.JLabel();
        faNameL = new javax.swing.JLabel();
        lNameT = new javax.swing.JTextField();
        parentT = new javax.swing.JTextField();
        gNameT = new javax.swing.JTextField();
        mNameT = new javax.swing.JTextField();
        genderCB = new javax.swing.JComboBox();
        schoolYearL = new javax.swing.JLabel();
        schl = new javax.swing.JLabel();
        IDNoT = new javax.swing.JTextField();
        IDNoL = new javax.swing.JLabel();
        mNameL1 = new javax.swing.JLabel();
        cNo = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        mNameL2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        save = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Add Summer Student");
        setResizable(false);

        bannerL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/banner.jpg"))); // NOI18N
        bannerL.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jSeparator2.setForeground(new java.awt.Color(0, 0, 0));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setAutoscrolls(true);

        genderL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        genderL.setText("Gender:");

        mNameL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        mNameL.setText("Middle Name:");

        gNameL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        gNameL.setText("Given Name:");

        fNameL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        fNameL.setText("Family Name:");

        faNameL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        faNameL.setText("Name of Parent:");

        lNameT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lNameT.setDisabledTextColor(java.awt.Color.black);
        lNameT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                lNameTKeyTyped(evt);
            }
        });

        parentT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        parentT.setDisabledTextColor(java.awt.Color.black);
        parentT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                parentTKeyTyped(evt);
            }
        });

        gNameT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        gNameT.setDisabledTextColor(java.awt.Color.black);
        gNameT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                gNameTKeyTyped(evt);
            }
        });

        mNameT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        mNameT.setDisabledTextColor(java.awt.Color.black);

        genderCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        genderCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        genderCB.setEditor(null);
        genderCB.setKeySelectionManager(null);

        schoolYearL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        schoolYearL.setText("0000-0000");

        schl.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        schl.setText("School Year:");

        IDNoT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        IDNoT.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        IDNoT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                IDNoTKeyTyped(evt);
            }
        });

        IDNoL.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        IDNoL.setText("I.D. Number:");

        mNameL1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        mNameL1.setText("Contact Number:");

        cNo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cNo.setDisabledTextColor(java.awt.Color.black);

        jTextField7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        mNameL2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        mNameL2.setText("Class Level:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(genderL)
                                .addGap(56, 56, 56)
                                .addComponent(genderCB, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(IDNoL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(IDNoT, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(fNameL)
                                .addGap(25, 25, 25)
                                .addComponent(lNameT, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(gNameL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(gNameT, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(65, 65, 65)
                                .addComponent(schl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(schoolYearL)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(mNameL)
                                .addGap(28, 28, 28)
                                .addComponent(mNameT, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(mNameL2)
                                .addGap(39, 39, 39)
                                .addComponent(jTextField7)))
                        .addContainerGap(20, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(faNameL)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(parentT, javax.swing.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(mNameL1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cNo, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(mNameL2)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(IDNoL)
                        .addComponent(schl)
                        .addComponent(schoolYearL)
                        .addComponent(IDNoT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fNameL)
                    .addComponent(lNameT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gNameT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mNameL)
                    .addComponent(mNameT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gNameL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(parentT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(faNameL)
                    .addComponent(mNameL1)
                    .addComponent(cNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(genderL)
                    .addComponent(genderCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jScrollPane1.setViewportView(jList1);

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
        jLabel1.setText("Summer Subject Offered");

        jScrollPane2.setViewportView(jList2);

        jButton1.setText("ADD");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("REMOVE");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("REMOVE ALL");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
        jLabel2.setText("Summer Subject Enrolled");

        jButton6.setText("ADD NEW SUBJECT");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(90, 90, 90)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 340, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(76, 76, 76))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                .addGap(884, 884, 884)
                .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(118, 118, 118)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jButton4.setText("Cancel");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        save.setText("Save");
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 1170, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 1022, Short.MAX_VALUE)
                        .addComponent(save)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addComponent(bannerL, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bannerL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(save, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lNameTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lNameTKeyTyped
        // TODO add your handling code here:
        String s = "[a-zA-Z0-9\\._\\-]{3,}";
        char c = evt.getKeyChar();
        
        if(c == KeyEvent.VK_SPACE) {
            if(lNameT.getText().isEmpty()) {
                evt.consume();
                JOptionPane.showMessageDialog(null, "Space bar not allowed as first character.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        
        if (!Character.isLetter(c) && c != KeyEvent.VK_SPACE && c != KeyEvent.VK_BACK_SPACE){
            evt.consume();
            JOptionPane.showMessageDialog(null, "Please enter allowed characters.", "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_lNameTKeyTyped

    private void parentTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_parentTKeyTyped
        // TODO add your handling code here:
        String s = "[a-zA-Z0-9\\._\\-]{3,}";
        char c = evt.getKeyChar();
        
        if(c == KeyEvent.VK_SPACE) {
            if(parentT.getText().isEmpty()) {
                evt.consume();
                JOptionPane.showMessageDialog(null, "Space bar not allowed as first character.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        
        if (!Character.isLetter(c) && c != KeyEvent.VK_SPACE && c != KeyEvent.VK_BACK_SPACE){
            evt.consume();
            JOptionPane.showMessageDialog(null, "Please enter allowed characters.", "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_parentTKeyTyped

    private void gNameTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_gNameTKeyTyped
        // TODO add your handling code here:
        String s = "[a-zA-Z0-9\\._\\-]{3,}";
        char c = evt.getKeyChar();
        
        if(c == KeyEvent.VK_SPACE) {
            if(gNameT.getText().isEmpty()) {
                evt.consume();
                JOptionPane.showMessageDialog(null, "Space bar not allowed as first character.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        
        if (!Character.isLetter(c) && c != KeyEvent.VK_SPACE && c != KeyEvent.VK_BACK_SPACE){
            evt.consume();
            JOptionPane.showMessageDialog(null, "Please enter allowed characters.", "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_gNameTKeyTyped

    private void IDNoTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_IDNoTKeyTyped
        // TODO add your handling code here:
        String s = "[a-zA-Z0-9\\._\\-]{3,}";
        char c = evt.getKeyChar();
        
        if(c == KeyEvent.VK_SPACE) {
            if(IDNoT.getText().isEmpty()) {
                evt.consume();
                JOptionPane.showMessageDialog(null, "Space bar not allowed as first character.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        
    }//GEN-LAST:event_IDNoTKeyTyped

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Object[] listData = jList1.getSelectedValues();
        int[] listNo = jList1.getSelectedIndices();

        for(int i = 0; i < listData.length; i++) {
            dlma.addElement(listData[i]);
        }
        
        for(int i = listNo.length - 1; i >= 0; i--) {
            dlmr.removeElementAt(listNo[i]);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Object[] listData = jList2.getSelectedValues();
        int[] listNo = jList2.getSelectedIndices();
        
        for(int i = 0; i < listData.length; i++) {
            dlmr.addElement(listData[i]);
        }
        
        for(int i = listNo.length - 1; i >= 0; i--) {
            dlma.removeElementAt(listNo[i]);
        }        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        for(int i = 0; i < dlma.getSize(); i++) {
            dlmr.addElement(dlma.getElementAt(i));
        } 
        dlma.removeAllElements();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
        // TODO add your handling code here:
       if(save.getText().equals("Update")) {
           String m = null;
            try {
                //String bd = (String) bYearCB.getSelectedItem() + "-" + (Digit(bMonthCB.getSelectedIndex() + 1)) + "-" + Digit(Integer.parseInt((String) bDayCB.getSelectedItem()));
                ArrayList<Object> sl = new ArrayList<Object>();
                for(int x = 0; x < dlma.getSize(); x++) {
                    sl.add(dlma.getElementAt(x));
                }
                //m = mi.getSummerSave(new Summer(IDNoT.getText(), lNameT.getText(), gNameT.getText(), mNameT.getText(), parentT.getText(), cNo.getText(), genderCB.getSelectedItem().toString(), schoolYearL.getText()), schoolYearL.getText(),  sl, cUser);
                m = mi.editManage("sumstud", id.getSumID(), new Summer(IDNoT.getText(), lNameT.getText(), gNameT.getText(), mNameT.getText(), parentT.getText(), cNo.getText(), genderCB.getSelectedItem().toString(), schoolYearL.getText()), cUser);
                if(m.contains("Failed")) {
                    JOptionPane.showMessageDialog(null, "Update Failed.", "Error", JOptionPane.ERROR_MESSAGE);
                    this.setVisible(false);
                } else {
                    JOptionPane.showMessageDialog(null, "Update Successful.", "Success", JOptionPane.INFORMATION_MESSAGE);
                    this.setVisible(false);
                }        
            }catch (Exception e) {
                e.printStackTrace();
            }
       } else if(save.getText().equals("Edit")) {
           save.setText("Update");
            lNameT.setEnabled(true);
            gNameT.setEnabled(true);
            mNameT.setEnabled(true);
            /*bMonthCB.setEnabled(false);
            bDayCB.setEnabled(false);
            bYearCB.setEnabled(false);*/
            parentT.setEnabled(true);
            cNo.setEnabled(true);
//            genderCB.setEnabled(true);
       } else if(save.getText().equals("Save")) {
           String m = null;
            try {
                ArrayList<Object> sl = new ArrayList<Object>();
                for(int x = 0; x < dlma.getSize(); x++) {
                    sl.add(dlma.getElementAt(x));
                }
                if(dlma.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "The Subject List is Empty", "Subject Added", JOptionPane.INFORMATION_MESSAGE);
                }else {
                    m = mi.getSummerSave(new Summer(IDNoT.getText(), lNameT.getText(), gNameT.getText(), mNameT.getText(), parentT.getText(), cNo.getText(), genderCB.getSelectedItem().toString(), schoolYearL.getText()), schoolYearL.getText(),  sl, cUser);
//                JOptionPane.showMessageDialog(null, m);
                               
                    if(id == null) {
                        int x = JOptionPane.showConfirmDialog(null, m + ", Do you still want to Add New Student?","Alert!",JOptionPane.YES_NO_OPTION);        
                        if(x == JOptionPane.YES_OPTION){
                            this.setVisible(false);                   
                            new SumStudent(cUser, mi, "", "").setVisible(true);                    
                        }                    
                    }  
                this.setVisible(false);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
       }
    }//GEN-LAST:event_saveActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
//        boolean p = false;
//        try {
//            while(!p) {
//            String  m = JOptionPane.showInputDialog(null,"Enter the new Summer Subject");
////            JOptionPane.showMessageDialog(null, m);           
////            if (m == null) {
//////                if(sm != null) sm.updateTable();
////                JOptionPane.showMessageDialog(null, "Enter a subject name", "Error", JOptionPane.ERROR_MESSAGE);
//////                jLabel11.setForeground(Color.red);
////            } else {
//                    if(m.length() == 0) {
//                        JOptionPane.showMessageDialog(null, "Enter a subject name", "Error", JOptionPane.ERROR_MESSAGE);
//                        p = false;
////                          if(ns != null) ns.updateTbl();
////                          jTextField6.setText("");
////                      }else {
////                          String m = mi.SumSubUpdate(s, jTextField6.getText());
////                          JOptionPane.showMessageDialog(null, m, "Subject Edit", JOptionPane.INFORMATION_MESSAGE);   
////                          this.setVisible(false);
//                    }else {                   
//                        String a = mi.SumSubjectAdd(m, ssy);                    
//                        JOptionPane.showMessageDialog(null, "Subject successfully added", "Subject Added", JOptionPane.INFORMATION_MESSAGE);
//                        p = true;
//                    }
//                
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        new SumSubject_Add(cUser, mi, null, null, this).setVisible(true);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton4ActionPerformed

    public String sMonth(String m) {
        if(m.matches("01")) {
            return "Jan";
        }else if(m.matches("02")) {
            return "Feb";
        }else if(m.matches("03")) {
            return "Mar";
        }else if(m.matches("04")) {
            return "Apr";
        }else if(m.matches("05")) {
            return "May";
        }else if(m.matches("06")) {
            return "Jun";
        }else if(m.matches("07")) {
            return "Jul";
        }else if(m.matches("08")) {
            return "Aug";
        }else if(m.matches("09")) {
            return "Sep";
        }else if(m.matches("10")) {
            return "Oct";
        }else if(m.matches("11")) {
            return "Nov";
        }else {
            return "Dec";
        }
    }
    
    public String Digit(int d) {
        String res = null;
        if (d < 10) {
            res = ("0" + d);
        } else {
            res = ("" + d);
        }
        return res;
    }           
    
    
    public void updateTbl() {
        try {
//            smList = mi.SSList();
            smList = mi.SumList(ssy);
            ArrayList<SumSubject> ss = new ArrayList<SumSubject>();
            for(int x = 0; x < smList.size(); x++) {
                ss.add((SumSubject) smList.get(x));
            }
            
            dlmr = new DefaultListModel();
            jList1.setModel(dlmr);
            for(int x = 0; x < ss.size(); x++) {
                if(id != null) {
                    if(!dlma.contains(ss.get(x).getSumSub())) {
                        dlmr.addElement(ss.get(x).getSumSub());
                    }
                }else {
                        dlmr.addElement(ss.get(x).getSumSub());                    
                }
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SumStudent(cUser, mi, ae, ssy).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel IDNoL;
    private javax.swing.JTextField IDNoT;
    private javax.swing.JLabel bannerL;
    private javax.swing.JTextField cNo;
    private javax.swing.JLabel fNameL;
    private javax.swing.JLabel faNameL;
    private javax.swing.JLabel gNameL;
    private javax.swing.JTextField gNameT;
    private javax.swing.JComboBox genderCB;
    private javax.swing.JLabel genderL;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField lNameT;
    private javax.swing.JLabel mNameL;
    private javax.swing.JLabel mNameL1;
    private javax.swing.JLabel mNameL2;
    private javax.swing.JTextField mNameT;
    private javax.swing.JTextField parentT;
    private javax.swing.JButton save;
    private javax.swing.JLabel schl;
    private javax.swing.JLabel schoolYearL;
    // End of variables declaration//GEN-END:variables
}
